<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<style type="text/css">
			#selectImage {
				position: absolute;
				top: 50%;
				left: 50%;
				margin-top: -75px;
				margin-left: -75px;
			}
		</style>
	</head>

	<body style="background: #FFFFFF;">

		<header class="mui-bar mui-bar-nav" style="background: #3A46A1;">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: #FFFFFF;"></a>
			<h1 class="mui-center mui-title" style="color: #FFFFFF; font-size: 20px; font-weight: bolder;">SAGAWA</h1>
		</header>

		<div class="mui-content" style="background: #FFFFFF; width: 100%; height: 100%; background-color: #FFFFFF;">

			<img id="selectImage" src="images/iconfont-tianjia.png" height="150px" width="150px">

		</div>
		<script src="js/mui.min.js"></script>
		<script type="text/javascript">
			(function($, doc) {

				var imageButton = doc.getElementById("selectImage");

				mui.plusReady(function() {

					imageButton.addEventListener('tap', function(event) {
						appendByGallery();

					});

					function appendByGallery() {
						plus.gallery.pick(function(path) {
							imageButton.src = path;
							compressImage(path);

						});
					};

					//压缩图片
					function compressImage(imagePath) {
						
						var name = imagePath.substr(imagePath.lastIndexOf('/') + 1);
						
						plus.zip.compressImage({
								src: imagePath,
								dst: "_Gosstech/" + name,
								quality: 20
							},
							function(event) {
								var path = event.target; // 压缩转换后的图片url路径，以"file://"开头
								var size = event.size; // 压缩转换后图片的大小，单位为字节（Byte）

								uploadImage(path);
							},
							function(error) {
								console.log(error.message);
								alert("Compress error!/r/n" + error.message);
							});
					};

					function uploadImage(imagePath) {
						var task = plus.uploader.createUpload("http://101.127.215.106:8101/SA_Mobile_Website/uploadFileMerchant.jsp", {
								method: "POST",
								blocksize: 204800,
								priority: 100
							},
							function(t, status) {
								// 上传完成
								if(status == 200) {
									alert("Upload success: " + t.url);
								} else {
									alert("Upload failed: " + status);
								}
							}
						);
						task.addFile("imagePath", {
							key: "subfolder"
						});
						task.start();
					};

					

				});

			}(mui, document));
		</script>
	</body>

</html>